import 'package:kkhousekeep/net/base_connect.dart';
import 'package:kkhousekeep/tools/dialog_util.dart';

import '../models/authorization_cities_entity.dart';
import '../models/authorization_community_entity.dart';
import '../models/base_respond_entity.dart';
import 'api.dart';

class AuthorizationConnect extends BaseConnect {
  Future<CitiesEntity?> getCityList() async {
    var response = await get(Api.cityList);
    if (response.body == null) {
      DialogUtil.showNetworkError();
      return Future.value();
    }
    return Future.value(CitiesEntity.fromJson(response.body));
  }

  Future<CommunityEntity?> getCommunities(
      String cityName, String keyword) async {
    var response = await get(Api.cityDetail,
        query: {"city": cityName, "keyword": keyword});
    if (response.body == null) {
      DialogUtil.showNetworkError();
      return Future.value();
    }
    return Future.value(
      CommunityEntity.fromJson(response.body),
    );
  }

  Future<BaseRespondEntity?> submitInformation({
    required String phone,
    required String name,
    required String iDCardType,
    required String iDCard,
    required String enterTime,
    required String image,
    required int roomID,
    required int cID,
  }) async {
    var response = await post(
      Api.submitRoomInformation,
      {
        "phone": phone,
        "name": name,
        "iDCardType": iDCardType,
        "iDCard": iDCard,
        "enterTime": enterTime,
        "image": image,
        "roomID": roomID,
        "cID": cID
      },
    );
    if (response.body == null) {
      DialogUtil.showNetworkError();
      return Future.value();
    }
    return BaseRespondEntity.fromJson(response.body);
  }
}
